﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using T.FAS.Runtime.Metadata.Entity.DataModel;
using T.FAS.Runtime.Metadata.Entity;

namespace T.FAS.Runtime.DataAccess.SQLDom
{
    /// <summary>
    /// 掩码控制上下文类
    /// </summary>
    public class MaskControlContext: AuthControlContext
    {
        /// <summary>
        /// 是否需要查询真实值
        /// </summary>
        protected bool IsNeedQueryMaskRealData { get; private set; } = false;

        /// <summary>
        /// 是否查询全部列
        /// </summary>
        protected bool IsAll { get; private set; }

        /// <summary>
        /// 查询的列名
        /// </summary>
        protected List<string> Columns { get; private set; }

        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="isNeedQueryMaskRealData"></param>
        /// <param name="isAll"></param>
        public void InitMaskControl(bool isNeedQueryMaskRealData, bool isAll, List<string> columns)
        {
            IsNeedQueryMaskRealData = isNeedQueryMaskRealData;
            IsAll = isAll;
            Columns = columns;
        }

        /// <summary>
        /// 判断是否返回掩码真实值
        /// </summary>
        /// <param name="dataColumn"></param>
        /// <returns>true:可以返回真实值，false:不返回真实值</returns>
        public bool IsCanGetRealData(DataColumn dataColumn)
        {
            //掩码改造 2024-08-14：有权限情况下，全部返回明文
            return true;
            if (!IsNeedQueryMaskRealData) return false;
            if (dataColumn == null)
            {
                throw new Exception($"dataColumn cannot be null");
            }
            if (IsAll) return true;
            return Columns.Any(col => string.Equals(col, dataColumn.ColumnName));
        }
    }
}